import 'package:equatable/equatable.dart';
import 'package:backend.purchases/domain/entities/app_store_api/app_store_api_transaction_revocation_reason.dart';

class AppStoreApiTransactionRevocationReasonDto extends Equatable {
  const AppStoreApiTransactionRevocationReasonDto._internal({
    required this.revocationReasonCode,
  });

  final int? revocationReasonCode;

  @override
  List<Object?> get props {
    return [
      revocationReasonCode,
    ];
  }

  factory AppStoreApiTransactionRevocationReasonDto.fromCode(int revocationReasonCode) {
    return AppStoreApiTransactionRevocationReasonDto._internal(
      revocationReasonCode: revocationReasonCode,
    );
  }

  AppStoreApiTransactionRevocationReason toEntity() {
    if (revocationReasonCode == 0) {
      return AppStoreApiTransactionRevocationReason.issueWithinApp;
    }

    if (revocationReasonCode == 1) {
      return AppStoreApiTransactionRevocationReason.otherReason;
    }

    throw UnimplementedError();
  }
}
